package com.mock.mockito.service;

import com.mock.mockito.dao.EmployeeRepository;
import com.mock.mockito.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    EmployeeRepository employeeRepository;

    public Employee save(Employee employee) {
        //...
        if (employee != null){
            Employee save = employeeRepository.save(employee);
            return save;
        }else {
            throw new NullPointerException("the employee is not allowed be null");
        }
    }

    public List<Employee> findAll() {
        //...
        List<Employee> all = (List<Employee>) employeeRepository.findAll();
        return all;
    }

    public void deleteById(Integer id) {
        //...
        if (id != null){
            employeeRepository.deleteById(id);
        }else {
            throw new NullPointerException("the id is not allowed be null");
        }
    }

    public void deleteAll() {
        //...
        employeeRepository.deleteAll();
    }
}
